const timer = {
  time: null,
}

// 设置定时器方法
timer.addTimer = id => {
  const el = document.getElementById(id)

  if (!el) return

  const elHeight = el.offsetHeight
  const sHeight = el.scrollHeight

  if (!(sHeight - elHeight > 0)) return

  timer.timer = setInterval(() => {
    if (el.scrollTop < sHeight - elHeight) {
      el.scrollTop++
    } else {
      el.scrollTop = 0
    }
  }, 100)
}

// 清除定时器方法
timer.clearTimer = () => {
  if (timer.timer) {
    clearInterval(timer.timer)
  }
}

export default timer
